package com.appsindy.common.action;

import java.util.ArrayList;
import java.util.List;

import com.appsindy.reserv.bo.HtGlobalListValue;
import com.appsindy.reserv.bo.HtGlobalType;
import com.appsindy.reserv.dao.GlobalListValueDAO;

public class MasterGlobalValuesAction extends AppsindyBaseAction implements IManageTab {
	
	private int typeId;
	private String typeName;
	private HtGlobalListValue globalValue;

	private List<HtGlobalType> typesList;
	private List<HtGlobalListValue> valuesList;

	private GlobalListValueDAO globalListValueDAO;
	
	public String execute() {
		//log.info("Init GlobalValues ...");
		getSession().put(S_TAB_CODE, MNG_GLOBAL);
		
		setTypesList(getGlobalListValueDAO().getAllTypes());
		if(getTypeName() != null && !"".equals(getTypeName().trim())){
			setValuesList(getGlobalListValueDAO().getValuesByType(getTypeName()));
		} else{
			setValuesList(new ArrayList<HtGlobalListValue>());
		}
		return SUCCESS;
	}
	
	public String save(){
		log.info("Id = " + globalValue.getListValueId());
		log.info("Value = " + globalValue.getListValueName());
		log.info("Desc = " + globalValue.getListValueDesc());
		log.info("Type Id = " + typeId + ", Type Name = " + typeName);
		if(globalValue.getListValueId() > 0){
			getGlobalListValueDAO().updateGlobalValue(globalValue);
		} else{
			globalValue.setListTypeId(typeId);
			getGlobalListValueDAO().insertGlobalValue(globalValue);
		}
		return execute();
	}

	public HtGlobalListValue getGlobalValue() {
		return globalValue;
	}
	public void setGlobalValue(HtGlobalListValue globalValue) {
		this.globalValue = globalValue;
	}

	public List<HtGlobalType> getTypesList() {
		return typesList;
	}
	public void setTypesList(List<HtGlobalType> typesList) {
		this.typesList = typesList;
	}

	public List<HtGlobalListValue> getValuesList() {
		return valuesList;
	}
	public void setValuesList(List<HtGlobalListValue> valuesList) {
		this.valuesList = valuesList;
	}
	
	public void setGlobalListValueDAO(GlobalListValueDAO globalListValueDAO) {
		this.globalListValueDAO = globalListValueDAO;
	}
	public GlobalListValueDAO getGlobalListValueDAO() {
		return globalListValueDAO;
	}

	public int getTypeId() {
		return typeId;
	}
	public void setTypeId(int typeId) {
		this.typeId = typeId;
	}

	public String getTypeName() {
		return typeName;
	}
	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}
    
}
